package com.ljx.funchat.common.event.listener;

import com.ljx.funchat.common.event.MessageSendEvent;
import com.ljx.funchat.transaction.config.RabbitMQConfig;
import com.ljx.funchat.transaction.domain.dto.MsgSendMessageDTO;
import com.ljx.funchat.transaction.service.RabbitMqProducer;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.event.EventListener;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;

/**
 * 发送消息监听器
 */
@Slf4j
@Component
public class MessageSendListener {

    @Autowired
    private RabbitMqProducer rabbitMqProducer;

    @Async
    @EventListener(classes = MessageSendEvent.class)
    public void messageRoute(MessageSendEvent event) {
        Long msgId = event.getMsgId();
        Long uid = event.getUid();

        rabbitMqProducer.sendMsg(RabbitMQConfig.MSG_QUEUE, new MsgSendMessageDTO(msgId, uid));
    }

}
